/**
 * Created by admin on 2017/7/13.
 */
(function () {
    var module = {};
    var tools = Tools();
    var testList = ['r_1', 'r_2', 'r_3', 'r_4', 'r_5', 'r_6', 'r_7', 'r_8'];
    var answerObj={};
    var answerList =[];
    module.init = function () {
        tools.isOpenAccount(); 
        $("#mCSB_1").mCustomScrollbar({
            scrollButtons:{
                enable:true
            }
        });
        tools.getUserInfo();
        getData();
    };


    function getData() {
        $(":radio").click(function(){
            for (var i = 0; i < testList.length; i++) {
                var valueL = $('input[name=' + testList[i] + ']:checked').val();
                if (valueL != undefined & valueL != null & valueL != '') {
                    var key=testList[i];
                    key=key.charAt(key.length-1);
                    answerObj[key]=valueL;
                } else {
                   return;
                }
            }
            answerList=[];
            for(var m in answerObj){
               answerList.push(answerObj[m]);
            }
            var answers= answerList.join("");
            if(answerList.length==8){
                $('.crisk_btn').removeClass('choose');

                $('.crisk_btn').on('click',function () {
                    tools.doPost(accountURL + tools.apiURL.testSubmit, {"answer":answers}, module.testSubmit);
                })
            }
        });
    }
    module.testSubmit=function (data) { 
        if(data.status==0){
            $('.crisk_main').hide();
            $('.crisk_answer').show();
          $('#answerStatus').text(data.data.result);
        }
    };


    module.init();
})();
